// This File is part of the "nyaqt" Project
// 
// Copyright  2009 sometmes@gmail.com
// All rights reserved
// 
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SvnWcUI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonReplace_Click(object sender, EventArgs e)
        {
            WcReplace wc = new WcReplace();
            wc.Source = textBoxSource.Text;
            wc.Target = textBoxTarget.Text;
            try
            {
                buttonReplace.Enabled = false;
                wc.Exec();
                MessageBox.Show("Export finished.                               ","Export finished");
            }
            finally
            {
                buttonReplace.Enabled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string tmp = textBoxSource.Text;
            textBoxSource.Text = textBoxTarget.Text;
            textBoxTarget.Text = tmp;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length == 3)
            {
                textBoxSource.Text = args[1];
                textBoxTarget.Text = args[2];
            }

        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        TextBox _currentConcreteTarget = null;

        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            //string[] formats = e.Data.GetFormats();
            //foreach (string format in formats)
            //{
            //    object o = e.Data.GetData(format);
            //}
            string[] dropped = e.Data.GetData("FileDrop") as string[];
            if (dropped.Length == 2)
            {
                textBoxSource.Text = dropped[0];
                textBoxTarget.Text = dropped[1];
            }
            else if (dropped.Length == 1)
            {
                _currentConcreteTarget.Text = dropped[0];
            }
        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Link;
            if (sender != this)
                _currentConcreteTarget = sender as TextBox;
        }

        private void textBoxSource_DragLeave(object sender, EventArgs e)
        {
            _currentConcreteTarget = null;
        }
    }
}
